package com.github.boluo1230.wechat.controller;

import com.github.boluo1230.wechat.base.ServerResponse;
import com.github.boluo1230.wechat.entity.AutoReplyKeywordsInfo;
import com.github.boluo1230.wechat.entity.BaseReplyInfo;
import com.github.boluo1230.wechat.service.mp.AutoReplyService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Code Farmer
 * @date 2019/10/25 14:56
 */
@RestController
@RequestMapping("/auto/reply")
@AllArgsConstructor
public class AutoReplyController {

    private final AutoReplyService autoReplyService;

    /**
     * 获取自动回复基础配置（关注回复，默认回复）列表
     *
     * @param appId
     * @return
     */
    @GetMapping("/info")
    public ServerResponse getAutoReplyInfo(String appId,
                                           @RequestParam(required = false, defaultValue = "1") int pageNo,
                                           @RequestParam(required = false, defaultValue = "10") int pageSize) {
        return ServerResponse.createBySuccess(autoReplyService.getMpAutoReplyInfoOnPage(appId, pageNo, pageSize));
    }

    /**
     * 回复规则列表
     *
     * @param appId
     * @param status
     * @return
     */
    @GetMapping("/keywords/list")
    public ServerResponse getAutoReplyInfo(String appId, Integer status) {
        return ServerResponse.createBySuccess(autoReplyService.getAutoReplyKeywordsList(appId, status));
    }

    /**
     * 上下线
     *
     * @param appId
     * @param ruleId
     * @param status
     * @return
     */
    @GetMapping("/keywords/modify/status")
    public ServerResponse modifyStatus(String appId, String ruleId, Integer status) {
        long result = autoReplyService.modifyStatus(appId, ruleId, status);
        return result > 0 ? ServerResponse.createBySuccess() : ServerResponse.createByError();
    }

    /**
     * 修改公众号自动回复规则条目
     *
     * @param autoReplyKeywordsInfo
     * @return
     */
    @PostMapping("/keywords/save")
    public ServerResponse saveAutoReplyKeywordsInfo(@RequestBody AutoReplyKeywordsInfo autoReplyKeywordsInfo) {
        long result = autoReplyService.saveAutoReplyKeywordsInfo(autoReplyKeywordsInfo);
        return result > 0 ? ServerResponse.createBySuccess() : ServerResponse.createByError();
    }

    /**
     * 修改公众号自动回复基础配置
     *
     * @param baseReplyInfo
     * @return
     */
    @PostMapping("/base/reply/save")
    public ServerResponse saveBaseReplyInfo(@RequestBody BaseReplyInfo baseReplyInfo) {
        long result = autoReplyService.saveBaseReplyInfo(baseReplyInfo);
        return result > 0 ? ServerResponse.createBySuccess() : ServerResponse.createByError();
    }

}
